package com.admin.business.pay;


import com.admin.utils.PayUtility;
import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import com.zmbsms.os.core.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("payTestSes")
@Slf4j
public class pay {

//	测试
	@OpenApi
	public Return payTest(CDO cdoRequest) {

		String mweb = cdoRequest.getString("mweb");
		cdoRequest.set("body", "测试");
		if (StringUtils.isNotEmpty(mweb)){
			cdoRequest.set("mweb", mweb);
		}
		cdoRequest.set("attach", "测试-支付");

		String notifyUrl = cdoRequest.getString("cdoRequest");

		if (notifyUrl==null){
			notifyUrl = "https://admin.515f.com/api/rest/v1/venusPortalQuestionTypeService/deleteDtsinfoById"; //随便拿的一个 回调我没写
		}

		cdoRequest.set("sNotifyUrl", notifyUrl);

//		微信获取二维码地址
		Return paySign = PayUtility.getWXPaySign(cdoRequest);
		return paySign;
	}


	@OpenApi
	public Return payWXPayById(CDO cdoRequest){
		Map<String, String> payInfo = PayUtility.getWXPayById(cdoRequest);
		String trade_state = payInfo.get("trade_state");
		if ("SUCCESS".equals(trade_state)) {//SUCCESS—支付成功
			return Return.valueOf(0,"支付成功");
		}
		return Return.valueOf(-200,"支付失败");
	}



}
